<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
    <el-form label-position="right" :model="repairRequestForm" :label-width="formLabelWidth" disabled="disabled">
      <el-row>
        <el-col :span="11">
          <el-form-item label="楼栋名称">
            <el-input v-model="repairRequestForm.buildingName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="单元房号">
            <el-input v-model="repairRequestForm.roomNumber"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="问题描述">
            <el-input v-model="repairRequestForm.description"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="报修时间">
            <el-input v-model="repairRequestForm.requestTime"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="状态">
            <el-select v-model="repairRequestForm.status" placeholder="请选择状态">
              <el-option label="待处理" :value="10"></el-option>
              <el-option label="处理中" :value="20"></el-option>
              <el-option label="已完成" :value="30"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="维修保养人员">
            <el-input v-model="repairRequestForm.staffName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="备注">
            <el-input v-model="repairRequestForm.remark"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="完成时间">
            <el-input v-model="repairRequestForm.finishTime"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="创建时间">
            <el-input v-model="repairRequestForm.createTime"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="最后修改时间">
            <el-input v-model="repairRequestForm.modifyTime"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="12" :offset="6">
          <div class="form-button-container">
            <el-button @click="onBack" type="primary">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import {defineEmits, defineProps, onMounted, reactive, ref, inject, toRefs} from 'vue';
import repairRequestApi from '@/api/repairRequestApi'
import type {RepairRequest} from "@/types/resp/repairRequest";
import type {Id} from "@/types/id"

const repairRequestForm = reactive<Partial<RepairRequest>>({});
const props = defineProps<Id>()
const emit = defineEmits<{
  (e: 'closeRepairRequestViewEvent'): void;
}>()
const formLabelWidth = ref<string>('')

onMounted(() => {
  initRepairRequestById(props.id)
  const globalState = inject('globalState', {} as { formLabelWidth?: string })
  if (!globalState) {
    throw new Error('globalState is not provided');
  }
  const globalStateRefs = toRefs(globalState)
  if (globalStateRefs.formLabelWidth) {
    formLabelWidth.value = globalStateRefs.formLabelWidth.value || ''
  }
})

const initRepairRequestById = async (id: number) => {
  const resp = await repairRequestApi.findById(id)
  if (resp && resp.code === 1 && resp.data) {
    Object.assign(repairRequestForm, resp.data)
  }
}
const onBack = () => {
  emit('closeRepairRequestViewEvent')
}
</script>

<style lang="scss">
</style>